package com.atguigu.gmall.web.all.controller;

import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.client.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class CartController {

    @Autowired
    private ProductFeignClient productFeignClient;
    //  http://cart.gmall.com/addCart.html?skuId=21&skuNum=1
    @GetMapping("addCart.html")
    public String addCart(HttpServletRequest request){
        //  远程调用获取到skuInfo
        SkuInfo skuInfo = productFeignClient.getSkuInfo(Long.parseLong(request.getParameter("skuId")));
        //  skuInfo skuNum
        request.setAttribute("skuInfo",skuInfo);
        request.setAttribute("skuNum",request.getParameter("skuNum"));
        //  返回添加成功页面.
        return "cart/addCart";
    }

    //  购物车列表控制器
    @GetMapping("/cart.html")
    public String cartList(){
        //  只需要返回购物车列表页面即可。页面会自动访问service-cart 微服务控制器！
        return "cart/index";
    }
}
